#include <xp/bas/stdio.h>
#include <xpp/bas/HashTable.h>
#include <xpp/bas/String.h>

#ifdef __linux
#include <mcheck.h>
#endif

using namespace xpp::bas;

extern "C" {

static int __main ();

int xp_main ()
{
#ifdef __linux
	mtrace ();
#endif	

	__main ();

#ifdef __linux
	muntrace ();
#endif	
	return 0;
}

static int __main ()
{
	HashTable<String,int> table;
	HashTable<String,int> table2;

	table.put (XP_TEXT("key01"), 100);
	table.put (XP_TEXT("key02"), 101);
	table.put (XP_TEXT("key03"), 102);
	table.put (XP_TEXT("key04"), 103);
	table.put (XP_TEXT("key05"), 104);
	table.put (XP_TEXT("key06"), 105);
	table.put (XP_TEXT("key07"), 106);
	table.put (XP_TEXT("key08"), 107);
	table.put (XP_TEXT("key09"), 108);
	table.put (XP_TEXT("key10"), 109);
	//table.remove (XP_TEXT("key1"));

	for (xp_size_t i = 0; i < table.bucketSize(); i++) {
		HashTable<String,int>::Bucket& b = table.bucket(i);
		for (HashTable<String,int>::Bucket::Node* np = b.head();
		     np != XP_NULL; np = np->forward()) {
			xp_printf (XP_TEXT("%s:%d\n"), (xp_char_t*)np->value.key, np->value.value);

		}
	}
	xp_printf (XP_TEXT("----------end of table1 -----------\n"));

	table2 = table;
	HashTable<String,int> table3 (table);

	for (xp_size_t i = 0; i < table2.bucketSize(); i++) {
		HashTable<String,int>::Bucket& b = table2.bucket(i);
		for (HashTable<String,int>::Bucket::Node* np = b.head();
		     np != XP_NULL; np = np->forward()) {
			xp_printf (XP_TEXT("%s:%d\n"), (xp_char_t*)np->value.key, np->value.value);
		}
	}
	xp_printf (XP_TEXT("----------end of table2 -----------\n"));

	for (xp_size_t i = 0; i < table3.bucketSize(); i++) {
		HashTable<String,int>::Bucket& b = table3.bucket(i);
		for (HashTable<String,int>::Bucket::Node* np = b.head();
		     np != XP_NULL; np = np->forward()) {
			xp_printf (XP_TEXT("%s:%d\n"), (xp_char_t*)np->value.key, np->value.value);
		}
	}
	xp_printf (XP_TEXT("----------end of table3 -----------\n"));

	xp_printf (XP_TEXT("%d\n"), table2[XP_TEXT("key08")]);
	xp_printf (XP_TEXT("%d\n"), table2[XP_TEXT("key03")]);
	xp_printf (XP_TEXT("-------------------------\n"));
	xp_printf (XP_TEXT("%d\n"), table3[XP_TEXT("key08")]);
	xp_printf (XP_TEXT("%d\n"), table3[XP_TEXT("key03")]);
	xp_printf (XP_TEXT("-------------------------\n"));

	/*
	const HashTable<String,int> ttt;
	*ttt.get(L"xxx") = 10;
	*/

	return 0;
}

}
